package gogogo.liwushuo.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;
import java.util.zip.Inflater;

import gogogo.liwushuo.R;
import gogogo.liwushuo.bean.XlsqBean;

/**
 * Created by Puck on 2016/7/21.
 */
public class LoadXlsqAdapter extends RecyclerView.Adapter<LoadXlsqAdapter.XlsqHolder>{
    private Context mcontext;
    private List<XlsqBean.DataBean.ItemsBean> mDatas;
    private DisplayImageOptions  mOptions;

    public LoadXlsqAdapter(Context context, List<XlsqBean.DataBean.ItemsBean> Datas){
        this.mcontext = context;
        this.mDatas = Datas;
        mOptions = new DisplayImageOptions.Builder()
                .showImageOnFail(R.mipmap.ic_launcher)
                .showImageOnLoading(R.mipmap.ic_launcher)
                .cacheOnDisk(true)
                .cacheInMemory(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .build();
    }
    public XlsqHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mcontext).inflate(R.layout.xlsq_cardview_layout,parent,false);
        return new XlsqHolder(view);
    }
    public void onBindViewHolder(XlsqHolder holder, int position) {
        XlsqBean.DataBean.ItemsBean bean = mDatas.get(position);
        ImageLoader.getInstance().displayImage(bean.getCover_image_url(),holder.iv_main_page,mOptions);
        holder.tv_title.setText(bean.getName());
        holder.tv_price.setText(bean.getPrice());
        holder.tv_favirte.setText(bean.getFavorites_count()+"");
    }
    public int getItemCount() {
        return mDatas == null? 0 : mDatas.size();
    }

    public void setList(List<XlsqBean.DataBean.ItemsBean> list) {
        this.mDatas = list;
    }

    public class XlsqHolder extends RecyclerView.ViewHolder{
           private TextView tv_title;
           private TextView tv_price;
           private TextView tv_favirte;
           private ImageView iv_main_page;
           private ImageView iv_favirte;
        public XlsqHolder(View itemView) {
            super(itemView);
            tv_title = (TextView) itemView.findViewById(R.id.tv_title_cardview);
            tv_price = (TextView) itemView.findViewById(R.id.tv_price_cardview);
            tv_favirte = (TextView) itemView.findViewById(R.id.tv_favrite_cardview);
            iv_main_page = (ImageView) itemView.findViewById(R.id.iv_cardview);
            iv_favirte = (ImageView) itemView.findViewById(R.id.iv_favrite_cardview);
        }
    }
}
